package com.baboba.rummy.cards;

import java.util.Comparator;

public class CardComparator implements Comparator<Card> {

	@Override
	public int compare(Card card1, Card card2) {
		if (card1 instanceof KingCard)
			return -1;
		
		if (card2 instanceof KingCard)
			return 1;
		
		ColorCard ccard1 = (ColorCard)card1;
		ColorCard ccard2 = (ColorCard)card2;
		
		if (ccard1.getColor() == ccard2.getColor())
			return ccard1.getNumber() - ccard2.getNumber();
		else{
			return ccard1.getColor().ordinal() - ccard2.getColor().ordinal();
		}
	}

}
